/** @odoo-module **/
const {
    markup,
    Component,
    onWillStart,
    useEnv,
    useSubEnv,
    useChildSubEnv,
    useRef,
    useState,
    mount,
    xml,
    whenReady,
    onMounted,
    onError,
    loadFile,
    onWillUpdateProps,
    useEffect,
    reactive,
    App,
    useComponent
} = owl;

import {Root} from './app.js'

let today = new Date();
let date = new Date(today.getTime() + (24 * 60 * 60 * 1000 * 2));
let year_month_day = `${date.getFullYear()}` + `-` + `${date.getMonth()+1}`.padStart(2, '0')+`-` + `${date.getDate()}`.padStart(2, '0');

let reactive_state = reactive({
    year_month_day
})

class Parent extends Component {
    setup() {

        onError(err => {
            console.log(err.cause.message);
            alert(err.cause.message);
        })

        this.state = useState(reactive_state);

    }


    PlanDayUpdateYearMonthDay(plan_day) {
        this.state.year_month_day = plan_day;
    }
}

Parent.template = xml`
    <Root year_month_day="state.year_month_day" PlanDayUpdateYearMonthDay.bind="PlanDayUpdateYearMonthDay"
     />
`
Parent.components = {
    Root,
}

whenReady(async () => {
    let templates = await loadFile('./xml/app.xml');
    let templates2 = await loadFile('./xml/components.xml');

    let app = new App(Parent, {
        env: {
            // UpdateYearMonthDay(y_m_d) {
            //     reactive_state.year_month_day = y_m_d;
            // }
        },
        dev: true,
    });

    app.addTemplates(templates);
    app.addTemplates(templates2);

    app.mount(document.body);

})

